'''
    网格节点
'''

import numpy as np
from scipy import interpolate
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
np.set_printoptions(threshold=np.inf)
x,y=np.meshgrid(np.arange(100,501,100),np.arange(100,401,100))
z=np.array([[636,697,624,478,450],[698,712,630,478,420],[680,674,598,412,400],[662,626,552,334,310]])
f=interpolate.interp2d(x,y,z,kind='cubic')
x_new,y_new=np.meshgrid(np.arange(100,500,10),np.arange(100,400,10))
xy_new=np.array([(xi,yi) for xi,yi in zip(np.array(x_new).reshape(1,1200)[0],np.array(y_new).reshape(1,1200)[0])])
res=np.array([(xy[0],xy[1],f(xy[0],xy[1])) for xy in xy_new])
#print(res)
s_res=sorted(res,key=lambda x:x[2],reverse=True)
print("max:",s_res[0])
# 纵向切片
#x_p=np.array(res[:,0]).reshape(30,40)
z_new=np.array([f(xi,yi) for xi,yi in zip(np.array(x_new).reshape(1,1200)[0],np.array(y_new).reshape(1,1200)[0])]).reshape(30,40)
print("max:",np.max(z_new))
fig=plt.figure()
ax=Axes3D(fig)
# x y z都是二维网格数组 shape相同
ax.plot_surface(x_new,y_new,z_new,cmap=plt.get_cmap('rainbow'))
ax.contour(x_new,y_new,z_new,zdir='z',offset=-2,cmap='rainbow')
plt.show()

